package com.maxbill.hive.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @user maxbill
 * @date 2018/01/16
 * @func Jdbc操作工具类
 */
public class JdbcUtils {

	private static String driver = "org.apache.hive.jdbc.HiveDriver";
	private static String url = "jdbc:hive2://hdpc01:10000/default";
	private static String user = "root";
	private static String pass = "123456";

	// 打开连接
	public static Connection openConnection() {
		Connection conn = null;
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, pass);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}

	// 关闭连接
	public static void closeConnection(Statement stmt, Connection conn) {
		try {
			if (stmt != null) {
				stmt.close();
				stmt = null;
			}
			if (conn != null) {
				conn.close();
				conn = null;
			}
			System.out.println(">>>>>>>>>>>>>>>>>>>>:关闭连接成功...");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
